package com.gxsf.back.controller;

import com.gxsf.back.pojo.ReserList;
import com.gxsf.back.repo.ReserListRepository;
import com.gxsf.back.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Map;

/**
 * @Package: com.gxsf.back.controller
 * @ClassName: ReserListController
 * @Author: BeijiRonin
 * @CreateTime: 2021/5/3 22:40
 * @Description:
 */
@CrossOrigin
@RestController
@RequestMapping("/reser_json")
@Slf4j
@Api("预约时段接口")
public class ReserListController {
    @Autowired
    ReserListRepository reserListRepository;

    @PostMapping("/save")
    @ApiOperation("保存接口，可用于修改或新增")
    public ReserList save(@RequestBody Map<String, String> map) {
        String reserItem = map.get("reserItem");
        ReserList reserList = JsonUtil.jsonToJava(reserItem, ReserList.class);
        reserList.setCreateTime(new Timestamp(System.currentTimeMillis()));
        reserList.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        return reserListRepository.save(reserList);
    }

    @PostMapping("/delete")
    @ApiOperation("删除")
    public void delete(@RequestBody Map<String, String> map) {
        String reserItem = map.get("reserItem");
        ReserList reserList = JsonUtil.jsonToJava(reserItem, ReserList.class);
        reserListRepository.delete(reserList);
    }
}
